package com.zld.smarket.controller;

import com.zld.smarket.pojo.Goodsloss;
import com.zld.smarket.pojo.Shelvesdown;
import com.zld.smarket.pojo.Stock;
import com.zld.smarket.result.ExceptionMsg;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.OnshelvesService;
import com.zld.smarket.service.ShelvesdownService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/shelvesdown")
public class ShelvesdownController {
    @Autowired
    private ShelvesdownService shelvesdownService;
    @Autowired
    private OnshelvesService onshelvesService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseData findList(Integer page, Integer limit) {
        return shelvesdownService.findList(page, limit);
    }

    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public ResponseData search(String s,Integer page, Integer limit){
        return  shelvesdownService.search(s,page,limit);
    }

    @RequestMapping(value = "/totaldown",method = RequestMethod.GET)
    public Long totaldown(){
        return  shelvesdownService.totaldown();
    }

    @RequestMapping(value = "/setshelvesdown")
    public ResponseData setshelvesdown(Shelvesdown shelvesdown){
        Long i=shelvesdown.getShelvesdownNo();
        if(shelvesdownService.selectbyno(i)>0){
            return new ResponseData(ExceptionMsg.ADDERROR);
        }else {
            shelvesdown.setShelvesdownDate(new Date());

            Integer integer1 =onshelvesService.reduceNum(shelvesdown.getGoodsNo(),shelvesdown.getSupplierId(),shelvesdown.getShelvesNo(),shelvesdown.getShelvesdownNum());
            Integer integer = shelvesdownService.setshelvesdown(shelvesdown);
            return new ResponseData(ExceptionMsg.SUCCESS);
        }



    }
}
